package com.cn.transfer.controller;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

@RestController
public class FileController {

    private final ResourceLoader resourceLoader;

    public FileController(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @GetMapping(value = "/CHANJET_CHECK.txt", produces = MediaType.TEXT_PLAIN_VALUE)
    public ResponseEntity<String> getFileContent() throws IOException {
        Resource resource = resourceLoader.getResource("classpath:CHANJET_CHECK.txt");

        Scanner scanner = new Scanner(resource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
        String content = scanner.useDelimiter("\\A").next();
        scanner.close();

        return ResponseEntity.ok().body(content);
    }
    @GetMapping(value = "/WW_verify_eLNfdqlkyWQIh4bs.txt", produces = MediaType.TEXT_PLAIN_VALUE)
    public ResponseEntity<String> getFileContents() throws IOException {
        Resource resource = resourceLoader.getResource("classpath:WW_verify_eLNfdqlkyWQIh4bs.txt");

        Scanner scanner = new Scanner(resource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
        String content = scanner.useDelimiter("\\A").next();
        scanner.close();

        return ResponseEntity.ok().body(content);
    }
}